package com.yscz.peexcel.common;

import lombok.Data;

/**
 * 封装前台返回实体类
 *
 * @author achen
 * @create 2021-08-13 15:53
 */
@Data
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;

    private Result(T data) {
        this.data = data;
    }

    public Result() {
    }

    public static <T> Result<T> success(Integer code, String msg, T data) {
        Result<T> tResult = new Result<>(data);
        tResult.setCode(code);
        tResult.setMsg(msg);
        return tResult;
    }

    public static Result error() {
        Result tResult = new Result<>();
        tResult.setCode(500);
        tResult.setMsg("系统异常");
        return tResult;
    }

    public static Result error(String msg) {
        Result tResult = new Result<>();
        tResult.setCode(500);
        tResult.setMsg(msg);
        return tResult;
    }

    public static Result error(Integer code, String msg) {
        Result tResult = new Result<>();
        tResult.setCode(code);
        tResult.setMsg(msg);
        return tResult;
    }

    public static Result success(Integer code, String msg) {
        Result tResult = new Result<>();
        tResult.setCode(code);
        tResult.setMsg(msg);
        return tResult;
    }
}
